package com.wdb007.venus.svc.biz.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WechatXmlLoadUtil {
	private static Logger logger = LoggerFactory.getLogger(WechatXmlLoadUtil.class);
	static Properties prop = null;
	public static String PATH = System.getenv("VENUS_CONFIG_PATH") + File.separator + "wxpay_xml";
	static {
		prop = new Properties();
		try {
			File file = new File(PATH);
			BufferedReader reader = null;
			for (File fileDoc : file.listFiles()) {
				if(fileDoc.getName().endsWith("xml")) {
					reader = new BufferedReader(new FileReader(PATH + File.separator + fileDoc.getName()));
					StringBuffer buffer = new StringBuffer();
					String line = null;
					while ((line = reader.readLine()) != null) {
						buffer.append(line);
					}
					prop.put(fileDoc.getName().replace(".xml", ""), buffer.toString().replace(" ", "").replace("\t", "").trim());
					reader.close();
				}
			}
		} catch (IOException e) {
			logger.error("读取xml模板出错：" + e);
		}
	}

	public static String getValue(String key) {
		return prop.getProperty(key);
	}
	public static void main(String[] args) {
//		System.out.println(WechatXmlLoadUtil.getValue("unifiedorder"));
		System.out.println(getValue("unifiedorder"));
	}
}
